package com.oa.pm.controller;

import com.joneying.common.web.response.Resp;
import com.oa.pm.entity.SpecificHandoverItems;
import com.oa.pm.service.ISpecificHandoverItemsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;

/**
 * @author syb123
 * @since 2019-01-22
 */
@RestController
@RequestMapping("/specificHandoverItems")
@Api(description = "具体交接事项表模块")
public class SpecificHandoverItemsController extends BaseController {

    private final ISpecificHandoverItemsService specificHandoverItemsService;

    @Autowired
    public SpecificHandoverItemsController(ISpecificHandoverItemsService specificHandoverItemsService) {
        this.specificHandoverItemsService = specificHandoverItemsService;
    }

    /**
     * 查询列表
     *
     * @param page  页码
     * @param limit 每页多少条
     * @return Resp
     */
    @PostMapping("/findList")
    @CommonController
    @Description("查询所有")
    @ApiOperation(value = "查询（不传page则查询所有）")
    public Resp<List<SpecificHandoverItems>> findList(
            @ApiParam(value = "页码") @RequestParam(required = false) Integer page,
            @ApiParam(value = "查询条数") @RequestParam(required = false) Integer limit
    ) {
        return new Resp().success(specificHandoverItemsService.findList(page, limit));
    }

    /**
     * 根据Id查询
     *
     * @param id id
     * @return Resp
     */
    @PostMapping("/findById")
    @CommonController
    @Description("获取详细信息")
    @ApiOperation(value = "根据id查询")
    public Resp<SpecificHandoverItems> findById(@ApiParam(value = "id", required = true) @RequestParam String id) {
        return new Resp().success(specificHandoverItemsService.findSpecificHandoverItemsById(id));
    }


    /**
     * 新增
     *
     * @param specificHandoverItems SpecificHandoverItems
     * @return Resp
     */
    @PostMapping("/add")
    @CommonController
    @Description("新增")
    @ApiOperation(value = "新增")
    public Resp add(@ApiParam(value = "具体交接事项表对象") @RequestBody(required = false) SpecificHandoverItems specificHandoverItems) {
        if (specificHandoverItemsService.insert(specificHandoverItems)) {
            return new Resp().success();
        } else {
            return new Resp().failure();
        }
    }

    /**
     * 根据Id修改
     *
     * @param specificHandoverItems SpecificHandoverItems
     * @return Resp
     */
    @PutMapping("/update")
    @CommonController
    @Description("根据id修改")
    @ApiOperation(value = "根据id修改")
    public Resp update(@ApiParam(value = "具体交接事项表对象") @RequestBody(required = false) SpecificHandoverItems specificHandoverItems) {
        if (specificHandoverItemsService.updateById(specificHandoverItems)) {
            return new Resp().success();
        } else {
            return new Resp().failure();
        }
    }

    /**
     * 根据Id删除
     *
     * @param id id
     * @return Resp
     */
    @DeleteMapping("/{id}")
    @CommonController
    @Description("根据id删除")
    @ApiOperation(value = "根据id删除")
    public Resp delete(@ApiParam(value = "id", required = true) @PathVariable("id") String id) {
        SpecificHandoverItems specificHandoverItems = specificHandoverItemsService.selectById(id);
        if (specificHandoverItems != null && specificHandoverItems.getIsDeleted() == 2) {
            specificHandoverItems.setIsDeleted(1);
            if (specificHandoverItemsService.updateById(specificHandoverItems)) {
                return new Resp().success();
            }
            return new Resp().failure();
        }
        return new Resp().failure();
    }
}
